// =================================================================================================
//
//	CopyEngine Framework
//	Copyright 2012 Eran. All Rights Reserved.
//
//	This program is free software. You can redistribute and/or modify infoTree
//	in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================

package app.displayTree.fixer.text
{
    import flash.geom.Matrix;
    import flash.geom.Rectangle;

    public final class DisplayTreeTextFieldFixer
    {
        public function DisplayTreeTextFieldFixer()
        {
        }

        /**
         * 修复所有ShapeMeta的错误信息
         */
        public static function fixTextFieldMetaProperty(_allTextFieldMetaWarpVector:Vector.<TextFieldMetaWrap>):void
        {
            var length:int = _allTextFieldMetaWarpVector.length;
            for (var i:int = 0; i < length; i++) {
                doFixTextFieldMeta(_allTextFieldMetaWarpVector[i]);
            }
        }

        private static function doFixTextFieldMeta(_warp:TextFieldMetaWrap):void
        {
            var length:int = _warp.textFieldMeta.frameTransformMatrixArray.length;
            for (var i:int = 0; i < length; i++) {
                //V2::Textfile有偏移,需要修正,详情见有道笔记
                var matrix:Matrix = _warp.textFieldMeta.frameTransformMatrixArray[i].getMatrix();
                var re:Rectangle = _warp.sourceTarget.getBounds(_warp.sourceTarget);

                var newMatrix:Matrix = new Matrix();
                newMatrix.translate(re.x, re.y);
                newMatrix.concat(matrix);

                _warp.textFieldMeta.frameTransformMatrixArray[i].setMatrix(newMatrix);
            }
        }
    }
}
